package com.easymin.daijia.server.task;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Timer;

/**
 * @author zhyu
 * @date 2020/1/6 16:04
 */
public class MyTaskTestMain {

    public static void main(String[] args) {
        final Sign sign = new Sign();
        Map<Integer,Timer> taskMaps = new HashMap();
        for (int i = 0; i < 10; i++) {
            Timer timer = new Timer();
            Integer taskName = new Integer(i);
            MyTask task = new MyTask(sign, taskName, taskMaps);
            taskMaps.put(taskName, timer);
            timer.schedule(task, 0, 5000);
        }
        try {
            Thread.sleep(3000L);
            System.out.println(taskMaps);
            new Thread(){
                @Override
                public void run(){
                    Scanner sc = new Scanner(System.in);
                    String s = null;
                    while (true) {
                        try {
                            Thread.sleep(300);
                            while((s = sc.nextLine()).equals("stop")){
                                sign.setSuccess(true);
                                System.out.println("set true");
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
